<body>
<{$xajax_scripts}>
<form method='post' onsubmit='return check_form_pass();'><input type='hidden' name='op' value='analysis_save'>
<div class='form_title'><{$smarty.const.MI_ANALYZE_RESULT}></div>
<table align=center cellspacing='0' cellpadding='0' border='0'><tr><td>
<table align=center class='analysis_content' cellspacing='1' cellpadding='1' border="0">
          <tr>
            <td colspan=5> <table border=0 class='analysis_header'>
                <tr>
                  <td colspan=<{$serology_match_info|@count}>><{$smarty.const.MI_POSITIVE_WELL}>:
                    <font color="red"><{$display_primer_numbers}></font></td>
                </tr>
                <tr> <{foreach from=$serology_match_info key=serology_id item=info}> 
                  <td><b>HLA-<{$serology_id}> <{$smarty.const.MI_LOCUS}>: <font color= '#2c8abc'><{$info.match_count}></font></b></td>
                  <{/foreach}> </tr>
                <tr id='imperfect_counts' style='display:none;'> <{foreach from=$serology_match_info 
                  key=serology_id item=info}> 
                  <td style='border: 1px dotted #aaaaaa;'><b><{$smarty.const.MI_IMPERFECT_WELL}> HLA-<{$serology_id}> <{$smarty.const.MI_IMPERFECT_WELL2}>: <font color= '#2c8abc'><{$info.imperfect_count}></font></b></td>
                  <{/foreach}> </tr>
                <tr id='rare_counts' style='display: none'> <{foreach from=$serology_match_info 
                  key=serology_id item=info}> 
                  <td style='border: 1px dotted #aaaaaa;'><b><{$smarty.const.MI_RARE_ITEMS}> HLA-<{$serology_id}> <{$smarty.const.MI_RARE_ITEMS2}>: <font color= '#2c8abc'><{$info.rare_count}></font></b></td>
                  <{/foreach}></tr>
              </table>
             <{if $has_rare==true}>
               <input type='button' id="MI_DISPLAY_RARE_ITEMS" class='colorbutton-red' style="height: 25px;" value="<{$smarty.const.MI_DISPLAY_RARE_ITEMS}>&nbsp;" onclick='display_rare(this);'>
               <input type='button' id="MI_HIDE_RARE_ITEMS" class='colorbutton-red' style="height: 25px; display: none;" value="<{$smarty.const.MI_HIDE_RARE_ITEMS}>&nbsp;" onclick='display_rare(this);'>&nbsp;
             <{/if}>
             <{foreach from=$serology_match_info key=serology_id item=info}>
               <{if $info.match_count > 0 || $info.imperfect_count > 0 }>&nbsp;
                 <input type='button' class='colorbutton' style="height: 25px;" value="<{$smarty.const.MI_DISPLAY_IMPERFECT_ITEMS}>: <{$serology_id}>" onclick='display_imperfect_<{$serology_id}>(this);'>
               <{/if}>
             <{/foreach}></td>
          </tr>
          <tr>
            <td>&nbsp; <script>
function display_types_detail(pno)
{
    document.getElementById('line'+pno+'_serotype1').rows = 3;
    document.getElementById('line'+pno+'_serotype2').rows = 3;
    document.getElementById('line'+pno+'_genotypes').rows = 3;
    //document.getElementById('line'+pno+'_detail').style.display = '';
}
function hide_types_detail(pno)
{
    document.getElementById('line'+pno+'_serotype1').rows = 1;
    document.getElementById('line'+pno+'_serotype2').rows = 1;
    document.getElementById('line'+pno+'_genotypes').rows = 1;
    //document.getElementById('line'+pno+'_detail').style.display = 'none';
}
</script></td>
            <th><{$smarty.const.MI_SEROTYPE_1}></th>
            <th><{$smarty.const.MI_SEROTYPE_2}></th>
            <th><{$smarty.const.MI_GENOTYPES}></th>
            <th><{$smarty.const.MI_CHOOSES}></th>
          </tr>
          <{foreach from=$matchs item=match}> <{ foreach from=$match item=line}>
          <tr style='display: none;'>
		  <td> 
	      <input type='hidden' name='line<{$line.pno}>_serology_id' value='<{$line.serology_id}>'>
              <input type='hidden' name='line<{$line.pno}>_line_no1' value='<{$line.line_no1}>'>
              <input type='hidden' name='line<{$line.pno}>_line_no2' value='<{$line.line_no2}>'>
              <input type='hidden' name='line<{$line.pno}>_primer_numbers' value='<{$line.match_save_primer_numbers}>'>
              <input type='hidden' name='line<{$line.pno}>_frequency' value='<{$line.frequency}>'>
              <input type='hidden' name='line<{$line.pno}>_imperfect' value='<{$line.imperfect}>'>
              <input type='hidden' name='line<{$line.pno}>_rare' value='<{$line.rare}>'>
            </td>
          </tr>
          <{ if $line.imperfect == 'Y'}>
          <tr id='line_<{$line.pno}>' class='imperfect_line' style='display: none;'>
            <td style='padding-top: 4px; text-align: left;'><b><{$line.match_numbers}></b></td>
            <td><textarea class='imperfect_field' readonly style='background-color:<{$line.view_color}>;' cols=14 rows=1 id='line<{$line.pno}>_serotype1' name='line<{$line.pno}>_serotype1' onfocus='display_types_detail(<{$line.pno}>);' onblur='hide_types_detail(<{$line.pno}>);'><{$line.serotype1}></textarea></td>
            <td><textarea class='imperfect_field' readonly style='background-color:<{$line.view_color}>;' cols=14 rows=1 id='line<{$line.pno}>_serotype2' name='line<{$line.pno}>_serotype2' onfocus='display_types_detail(<{$line.pno}>);' onblur='hide_types_detail(<{$line.pno}>);'><{$line.serotype2}></textarea></td>
            <td><textarea class='imperfect_field' readonly style='background-color:<{$line.view_color}>;' cols=70 rows=1 id='line<{$line.pno}>_genotypes' name='line<{$line.pno}>_genotypes' onfocus='display_types_detail(<{$line.pno}>);' onblur='hide_types_detail(<{$line.pno}>);'><{$line.genotypes}></textarea>
              <div id='line<{$line.pno}>_detail' style='background-color:#000093;color:white;text-align:left;display:none;'>Line:
                <{$line.line_no1}>,<{$line.line_no2}> / Frequency: <{$line.frequency}></div></td>
            <td align="center"><input type='checkbox' class='checkbox' class='imperfect_field' style='background-color:<{$line.view_color}>;' name='line<{$line.pno}>_checked' value='true'></td>
          </tr>
          <{ elseif $line.rare == 'Y'}>
          <tr id='line_<{$line.pno}>' class='rare_line' style='display: none;'>
            <td style='padding-top: 4px; text-align: left;'><b><{$line.match_numbers}></b></td>
            <td><textarea class='rare_field' readonly style='background-color:<{$line.view_color}>;' cols=14 rows=1 id='line<{$line.pno}>_serotype1' name='line<{$line.pno}>_serotype1' onfocus='display_types_detail(<{$line.pno}>);' onblur='hide_types_detail(<{$line.pno}>);'><{$line.serotype1}></textarea></td>
            <td><textarea class='rare_field' readonly style='background-color:<{$line.view_color}>;' cols=14 rows=1 id='line<{$line.pno}>_serotype2' name='line<{$line.pno}>_serotype2' onfocus='display_types_detail(<{$line.pno}>);' onblur='hide_types_detail(<{$line.pno}>);'><{$line.serotype2}></textarea></td>
            <td><textarea class='rare_field' readonly style='background-color:<{$line.view_color}>;' cols=70 rows=1 id='line<{$line.pno}>_genotypes' name='line<{$line.pno}>_genotypes' onfocus='display_types_detail(<{$line.pno}>);' onblur='hide_types_detail(<{$line.pno}>);'><{$line.genotypes}></textarea>
              <div id='line<{$line.pno}>_detail' style='background-color:#000093;color:white;text-align:left;display:none;'>Line:
                <{$line.line_no1}>,<{$line.line_no2}> / Frequency: <{$line.frequency}></div></td>
            <td align="center"><input type='checkbox' class='checkbox' class='rare_field' style='background-color:<{$line.view_color}>;' name='line<{$line.pno}>_checked' value='true'></td>
          </tr>
          <{ else}>
          <tr id='line_<{$line.pno}>'>
            <td>&nbsp;</td>
            <td><textarea class='field' readonly style='background-color:<{$line.view_color}>;' cols=14 rows=1 id='line<{$line.pno}>_serotype1' name='line<{$line.pno}>_serotype1' onfocus='display_types_detail(<{$line.pno}>);' onblur='hide_types_detail(<{$line.pno}>);'><{$line.serotype1}></textarea></td>
            <td><textarea class='field' readonly style='background-color:<{$line.view_color}>;' cols=14 rows=1 id='line<{$line.pno}>_serotype2' name='line<{$line.pno}>_serotype2' onfocus='display_types_detail(<{$line.pno}>);' onblur='hide_types_detail(<{$line.pno}>);'><{$line.serotype2}></textarea></td>
            <td><textarea class='field' readonly style='background-color:<{$line.view_color}>;' cols=70 rows=1 id='line<{$line.pno}>_genotypes' name='line<{$line.pno}>_genotypes' onfocus='display_types_detail(<{$line.pno}>);' onblur='hide_types_detail(<{$line.pno}>);'><{$line.genotypes}></textarea>
              <div id='line<{$line.pno}>_detail' style='background-color:#000093;color:white;text-align:left;display:none;'>Line:
                <{$line.line_no1}>,<{$line.line_no2}> / Frequency: <{$line.frequency}></div></td>
            <td align="center"><input type='checkbox' class='checkbox' class='field' style='background-color:<{$line.view_color}>;' name='line<{$line.pno}>_checked' value='true'></td>
          </tr>
          <{ /if}> <{ /foreach}> <{/foreach}> <{if $has_manual_numbers }>
          <tr>
            <td></td>
            <td colspan=4 style='text-align:center;background-color: '#2c8abc';'><font color=white><b><{$smarty.const.MI_HINT_MANUAL_NUMBERS}></b></font></td>
          </tr>
          <{/if}>
          <!--tr>
            <td colspan="4" style="text-align: right;"><b><{$smarty.const.MI_FINAL}></b></td>
            <td><input type='checkbox' class='checkbox' id='final' name='final' value='true' checked /><input type='hidden' name='save_primer_numbers' value="<{$save_primer_numbers}>" /></td>
          </tr-->
        </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="center"><input name="submit" type='submit' class='btn_save' value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<{$smarty.const.MI_SAVE}>">
              <input name="button3" type='button' class='btn_uppage' onClick='history.go(-1);' value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<{$smarty.const.MI_BACK}>"></td>
          </tr>
        </table>
        <br>
        <table border="1" align="center" cellpadding='1' cellspacing='1' bordercolor="#cbe5f6" class='form_detail'>
          <script>

var SampleIDVerified = false;
var PatientIDVerified = true;

function checkIsValidDate(str)
{
  if (str == "")
     return true;
  var pattern = /^(\d{4})\-(\d{1,2})\-(\d{1,2})$/g;
  if(!pattern.test(str))
     return false;
  var arrDate = str.split("-");
  if(parseInt(arrDate[0],10) < 100)
     arrDate[0] = 2000 + parseInt(arrDate[0],10) + "";
  var date = new Date(arrDate[0],(parseInt(arrDate[1],10) -1)+"",arrDate[2]);
  if(date.getYear() == arrDate[0]
     && date.getMonth() == (parseInt(arrDate[1],10)-1)+""
     && date.getDate() == arrDate[2])
     return true;
  else
     return false;
}

function set_lot_no_value(lot_no)
{
    var obj = document.getElementById("lot_no");

    if (lot_no == '')
        obj.selectedIndex = 0;
    else if (obj != null)
    {
        try
        {
            obj.selectedIndex = 0;
            for (var i=0; i<obj.options.length; i++)
                if (obj.options[i].innerText.match(lot_no+" "))
                {
                    obj.selectedIndex = i;
                    break;
                }
        }
        catch (e)
        {
        }
    }
}

function clear_sample(clear_sample_id)
{
    SampleIDVerified = false;

    if (clear_sample_id)
    {
        document.getElementById("sample_id").value = '';
        try { document.getElementById("sample_id").focus(); }
        catch (e) {}
    }

    document.getElementById("kit_id").value = '<{$kit_id}>';
    document.getElementById("dna_ext_method").value = '';
    document.getElementById("dna_od").value = '';
    document.getElementById("comment").value = '';
    set_lot_no_value('<{$lot_no}>');

    document.getElementById("sample_hint").style.display = 'none';

    LastCheckSampleId = '';
}

function hint_sample_id_wrong_format()
{
    document.getElementById('sample_hint').style.display = '';
    document.getElementById('sample_hint').innerHTML = "<font class='field_hint' style='background-color: '#2c8abc';'><{$smarty.const.MI_SAMPLE_ID_WRONG_FORMAT}></font>";
}

function show_sample_not_exists()
{
    clear_sample();

    document.getElementById('sample_hint').style.display = '';
    document.getElementById('sample_hint').innerHTML = "<font class='field_hint'><{$smarty.const.MI_SAMPLE_NOT_EXISTS}></font>";

    clear_patient(true);
}

function show_sample_exists(kit_id,sample_id,dna_ext_method,dna_od,lot_no,comment,has_serotypes)
{
    clear_sample();

    if (!has_serotypes)
    {
        document.getElementById('sample_hint').style.display = '';
        document.getElementById('sample_hint').innerHTML = "<font class='field_hint'><{$smarty.const.MI_SAMPLE_EXISTS}></font>";
    }
    else
    {
        document.getElementById('sample_hint').style.display = '';
        document.getElementById('sample_hint').innerHTML = "<font class='field_hint' style='background-color: '#2c8abc';'><{$smarty.const.MI_SAMPLE_HAS_SEROTYPES}></font>";
    }

    if (document.getElementById("sample_id").value != sample_id)
        document.getElementById("sample_id").value = sample_id;

    document.getElementById("kit_id").value = kit_id;
    document.getElementById("dna_ext_method").value = dna_ext_method;
    document.getElementById("dna_od").value = dna_od;
    document.getElementById("comment").value = comment;
    set_lot_no_value(lot_no);
}

function clear_patient(clear_patient_id)
{
    PatientIDVerified = false;

    document.getElementById("patient_rowguid").value = 'false';

    if (clear_patient_id == true)
    {
        document.getElementById("institution").value = '<{$institution}>';
        document.getElementById("patient_id").value = '';
    }

    document.getElementById("ethnic").value = '';
    document.getElementById("first_name").value = '';
    document.getElementById("last_name").value = '';
    document.getElementById("sex_M").checked = false;
    document.getElementById("sex_F").checked = false;
    document.getElementById("age").value = '';

    document.getElementById("patient_hint").style.display = 'none';
}

function hint_patient_id_wrong_format()
{
    document.getElementById('patient_hint').style.display = '';
    document.getElementById('patient_hint').innerHTML = "<font class='field_hint' style='background-color: '#2c8abc';'><{$smarty.const.MI_PATIENT_ID_WRONG_FORMAT}></font>";
}

function show_patient_not_exists()
{
    clear_patient();

    document.getElementById('patient_hint').style.display = '';
    document.getElementById('patient_hint').innerHTML = "<font class='field_hint'><{$smarty.const.MI_PATIENT_NOT_EXISTS}></font>";
}

function show_patient_exists(rowguid,institution,patient_id,ethnic,first_name,last_name,sex,age)
{
    document.getElementById("patient_rowguid").value = rowguid;

    if (document.getElementById("institution").value != institution)
        document.getElementById("institution").value = institution;

    if (document.getElementById("patient_id").value != patient_id)
        document.getElementById("patient_id").value = patient_id;

    document.getElementById('patient_hint').style.display = '';
    document.getElementById('patient_hint').innerHTML = "<font class='field_hint'><{$smarty.const.MI_PATIENT_EXISTS}></font>";

    document.getElementById("ethnic").value = ethnic;
    document.getElementById("first_name").value = first_name;
    document.getElementById("last_name").value = last_name;

    document.getElementById("sex_M").checked = false;
    document.getElementById("sex_F").checked = false;

    if (sex == 'M')
        document.getElementById("sex_M").checked = true;
    else if (sex == 'F')
        document.getElementById("sex_F").checked = true;

    document.getElementById("age").value = age>0?age:'';
}

function do_add_lot(auto_focus)
{
    new_lot_no = document.getElementById("custom_add_lot_no").value;
    new_lot_expires = document.getElementById("custom_add_lot_expires").value;
    new_lot_expires = new_lot_expires.replace(/\//g, "-");

    if (new_lot_no == '' || new_lot_expires == '')
    {
        alert('<{$smarty.const.MI_REQUIRE_LOT_DATA}>');
        return false;
    }

    if (!checkIsValidDate(new_lot_expires))
    {
        alert('<{$smarty.const.MI_INVALID_DATETIME_FORMAT}>');
        return false;
    }

    for (var i=0; i<document.getElementById('lot_no').options.length; i++)
        if (document.getElementById('lot_no').options[i].innerText.replace(/\s-\s.*/, "") == new_lot_no)
        {
            document.getElementById('lot_no').selectedIndex = i;
            hide_add_lot(auto_focus);
            return true;
        }

    var objOption = new Option(new_lot_no + ' / <{$smarty.const.MI_KIT_LOT_EXPIRES}> ' + new_lot_expires);
    document.getElementById('lot_no').options.add(objOption, 1);

    document.getElementById('lot_no').selectedIndex = 1;
    hide_add_lot(auto_focus);

    return true;
}

function show_add_lot(auto_focus)
{
    document.getElementById("custom_add_lot_no").value = '';
    document.getElementById("custom_add_lot_expires").value = '';
    document.getElementById("list_lot_block").style.display = 'none';
    document.getElementById("add_lot_block").style.display = '';
    if (auto_focus == true)
        document.getElementById("custom_add_lot_no").focus();
}

function hide_add_lot(auto_focus)
{
    document.getElementById("add_lot_block").style.display = 'none';
    document.getElementById("list_lot_block").style.display = '';
    if (auto_focus == true)
        document.getElementById('lot_no').focus();
}

var LastCheckSampleId = '';

function ServerSync_GetSampleInfo()
{
    var sample_id = document.getElementById("sample_id").value;
    if (LastCheckSampleId != sample_id)
    {
        LastCheckSampleId = sample_id;
        if (sample_id != '')
            xajax_Ajax_GetSampleInfo(sample_id, '<{$kit_id}>');
        else
            SampleIDVerified = true;
    }
}

var LastCheckInstitution = '';
var LastCheckPatientId = '';

function ServerSync_GetPatientInfo()
{
    var institution = document.getElementById("institution").value;

    if (institution == '')
        institution = 'EMPTY';

    var patient_id = document.getElementById("patient_id").value;

    if (LastCheckInstitution != institution || LastCheckPatientId != patient_id)
    {
        LastCheckInstitution = institution;
        LastCheckPatientId = patient_id;
        if (patient_id != '')
            xajax_Ajax_GetPatientInfo(institution, patient_id);
        else
            PatientIDVerified = true;
    }
}

function check_form_pass()
{
    if (document.getElementById('institution').value == '')
        document.getElementById('institution').value = 'EMPTY';

    if (document.getElementById("add_lot_block").style.display == '')
    {
        if (document.getElementById("custom_add_lot_no").value != '')
        {
            if (!do_add_lot())
                return false;
        }
        else
            hide_add_lot();
    }

    if (document.getElementById('sample_id').value == '')
    {
        alert('<{$smarty.const.MI_ERROR_REQUIRE_SAMPLE_ID}>');
        document.getElementById('sample_id').focus();
        return false;
    }

    if (
        document.getElementById('patient_id').value != '' ||
        document.getElementById('ethnic').value != '' ||
        document.getElementById('first_name').value != '' ||
        document.getElementById('last_name').value != '' ||
        document.getElementById("sex_M").checked ||
        document.getElementById("sex_F").checked ||
        document.getElementById('age').value != '')
    {
        if (document.getElementById('institution').value == '' ||
            document.getElementById('patient_id').value == '' ||
            document.getElementById('first_name').value == '' ||
            document.getElementById('last_name').value == '')
        {
            alert('<{$smarty.const.MI_ERROR_REQUIRE_PATIENT_INFO}>');
            if (document.getElementById('institution').value == '')
                document.getElementById('institution').focus();
            else if (document.getElementById('patient_id').value == '')
                document.getElementById('patient_id').focus();
            else if (document.getElementById('first_name').value == '')
                document.getElementById('first_name').focus();
            else if (document.getElementById('last_name').value == '')
                document.getElementById('last_name').focus();
            return false;
        }
    }

    if (!SampleIDVerified)
    {
        ServerSync_GetSampleInfo();
        return false;
    }

    if (!PatientIDVerified)
    {
        ServerSync_GetPatientInfo();
        return false;
    }

    var HasChecked;

    if (document.getElementById('final').checked)
    {
<{foreach from=$serology_match_info key=serology_id item=info }>
        HasChecked = false;
        for (var i=0; i<<{$matchs_max_pno}>; i++)
            if (document.getElementById('line'+i+'_serology_id').value == '<{$serology_id}>' &&
                document.getElementById('line'+i+'_checked').checked)
            {
                if (HasChecked == true)
                {
                    alert('<{$smarty.const.MI_ERROR_REQUIRE_ONE_SEROLOGY}>');
                    return false;
                }
                HasChecked = true;
            }
        if (!HasChecked)
        {
            alert('<{$smarty.const.MI_ERROR_REQUIRE_ONE_SEROLOGY}>');
            return false;
        }

<{/foreach}>

        if (!confirm('<{$smarty.const.MI_FINAL_SAVE_CONFIRM}>'))
            return false;
    }

    return true;
}

</script>
          <tr> <{if $sample_exists}>
            <td nowrap background='<{$theme_url}>/images/form_detail_pic03.jpg' style="color: black; font-size: 8pt; text-align: right; font-weight: bold;"><{$smarty.const.MI_SAMPLE_ID}></td>
            <td><{$sample_id}> <input type='hidden' name='sample_id' value=''>
              <div id='sample_hint' style='display:none;'></div></td>
            <td nowrap background='<{$theme_url}>/images/form_detail_pic03.jpg' style="color: black; font-size: 8pt; text-align: right; font-weight: bold;"><{$smarty.const.MI_SELECT_KIT_ID}></td>
            <td><{$kit_id}> <input type='hidden' name='kit_id' value='<{$kit_id}>'></td>
            <{else}>
            <td nowrap background='<{$theme_url}>/images/form_detail_pic03.jpg' style="color: black; font-size: 8pt; text-align: right; font-weight: bold;"><{$smarty.const.MI_SAMPLE_ID}></td>
            <td><input size="20" maxlength=20 name='sample_id' value='' onFocus='clear_sample();' onKeyPress='clear_sample();' onBlur='ServerSync_GetSampleInfo();'>
              <div id='sample_hint' style='display:none;'></div></td>
            <td nowrap background='<{$theme_url}>/images/form_detail_pic03.jpg' style="color: black; font-size: 8pt; text-align: right; font-weight: bold;"><{$smarty.const.MI_SELECT_KIT_ID}></td>
            <td><{$kit_id}> <input type='hidden' name='kit_id' value='<{$kit_id}>'></td>
            <{/if}> </tr>
          <tr>
            <th><{$smarty.const.MI_DNA_EXT_METHOD}></th>
            <td><input size="20" maxlength=30 name='dna_ext_method' value=''></td>
            <th><{$smarty.const.MI_DNA_OD}></th>
            <td><input size="20" maxlength=12 name='dna_od' value=''></td>
          </tr>
          <tr>
            <th><{$smarty.const.MI_KIT_LOT_NO}></th>
            <td colspan=3><div id='list_lot_block'<{if count($lot_list) == 0}>
              style='display:none;'<{/if}>> <select name='lot_no'>
                <option></option><{foreach from=$lot_list item=line}>
                <option <{if $lot_no==$line.lot_no}> selected<{/if}>><{$line.lot_no}>
                / <{$smarty.const.MI_KIT_LOT_EXPIRES}> <{$line.lot_expires}></option><{/foreach}>
              </select> <input name="button" type='button' class='sbutton' onClick='show_add_lot(true);' value="&nbsp;<{$smarty.const.MI_ADD_LOT}>&nbsp;" /> </div> <div id='add_lot_block'
              <{if count($lot_list) > 0}> style='display:none;'<{/if}>> <input size="20" maxlength=200 name='custom_add_lot_no' value=''>
              &nbsp;<{$smarty.const.MI_KIT_LOT_EXPIRES}> <input size="10" maxlength=10 name='custom_add_lot_expires' value=''>
              &nbsp; <input name="button" type='button' class='sbutton' onClick='do_add_lot(true);' value="&nbsp;<{$smarty.const._ADD}>&nbsp;" />
              <input name="button" type='button' class='sbutton' onClick='hide_add_lot(true);' value="&nbsp;<{$smarty.const._CANCEL}>&nbsp;" /> </div>
            </td>
          </tr>
          <tr>
            <th><{$smarty.const.MI_TEST_BY}></th>
            <td><{$test_by}></td>
            <th><{$smarty.const.MI_TEST_DATE}></th>
            <td><{$test_date}></td>
          </tr>
          <tr>
            <td nowrap background='<{$theme_url}>/images/form_detail_pic02.jpg' style="color: black; font-size: 8pt; text-align: right; font-weight: bold;"><{$smarty.const.MI_COMMENT}></td>
            <td colspan=3><textarea name='comment' class='textarea' cols=74 rows=5></textarea></td>
          </tr>
          <tr style='display:none;'>
            <th><{$smarty.const.MI_INSTITUTION}></th>
            <td colspan=3><input size="70" maxlength=120 name='institution' value='<{$institution}>'></td>
          </tr>
          <tr>
            <td nowrap background="<{$theme_url}>/images/form_detail_pic03.jpg" style="color: black; font-size: 8pt; text-align: right; font-weight: bold;"><{$smarty.const.MI_PATIENT_ID}></td>
            <td><input size="20" maxlength=20 name='patient_id' value='' onFocus='clear_patient();' onKeyPress='clear_patient();' onBlur='ServerSync_GetPatientInfo();'>
              <input type='hidden' name='patient_rowguid' value='false'> <div id='patient_hint' style='display:none;'></div></td>
            <td nowrap background="<{$theme_url}>/images/form_detail_pic03.jpg" style="color: black; font-size: 8pt; text-align: right; font-weight: bold;"><{$smarty.const.MI_ETHNIC}></td>
            <td><input size="20" maxlength=20 name='ethnic' value=''></td>
          </tr>
          <tr>
            <th height="18"><{$smarty.const.MI_FIRST_NAME}></th>
            <td><input size="20" maxlength=50 name='first_name' value=''></td>
            <th><{$smarty.const.MI_LAST_NAME}></th>
            <td><input size="20" maxlength=50 name='last_name' value=''></td>
          </tr>
          <tr>
            <th><{$smarty.const.MI_SEX}></th>
            <td><input type='radio' class='radiobox' id='sex_M' name='sex' value='M'> <{$smarty.const._MALE}>
             <input type='radio' class='radiobox' id='sex_F' name='sex' value='F'> <{$smarty.const._FEMALE}></td>
            <th><{$smarty.const.MI_AGE}></th>
            <td><input size="20" maxlength=3 name='age' value=''></td>
          </tr>
          <{if !empty($sample_images) }>
          <tr id='sample_image_btns' style='display:none;'>
            <td></td>
            <td align=left valign=top nowrap colspan=3> <input type='hidden' name='img_rotate' value='<{$img_rotate}>'>
              <input type='hidden' name='img_zoom' value='<{$img_zoom}>'> <script>
var InitSample = false;

var SampleImageWidth = 0;
var SampleImageHeight = 0;

function InitSampleImage()
{
    try
    {
        InitSample = true;

        SampleImageWidth = document.getElementById("<{$sample_images.0.id}>").width;
        SampleImageHeight = document.getElementById("<{$sample_images.0.id}>").height;

        RotationVal = 1*document.getElementById('img_rotate').value;
        RotationVal = RotationVal % 4;
        document.getElementById('img_rotate').value = RotationVal;

        ZoomVal = Math.round(1*document.getElementById('img_zoom').value)/10;
        if (document.getElementById("<{$sample_images.0.id}>").width * ZoomVal < 200 ||
                document.getElementById("<{$sample_images.0.id}>").width * ZoomVal > 1024)
            ZoomVal = 1;
        document.getElementById('img_zoom').value = Math.floor(ZoomVal*10);

<{foreach from=$sample_images item=sample_img }>

        document.getElementById("<{$sample_img.id}>_div").style.filter="progid:DXImageTransform.Microsoft.BasicImage(Rotation=" + RotationVal + ");";
        document.getElementById("<{$sample_img.id}>").width = SampleImageWidth * ZoomVal;
        document.getElementById("<{$sample_img.id}>").height = SampleImageHeight * ZoomVal;
        document.getElementById("<{$sample_img.id}>_div").style.width = document.getElementById("<{$sample_img.id}>").width+4;
        document.getElementById("<{$sample_img.id}>_div").style.height = document.getElementById("<{$sample_img.id}>").height+4;
        document.getElementById("<{$sample_img.id}>_div").style.display="";

<{/foreach}>

        document.getElementById("sample_image_btns").style.display="";
    }
    catch (e)
    {
        location.reload();
    }
}
function ShowSampleImage()
{
    if (!InitSample)
        InitSampleImage();
    else
    {
<{foreach from=$sample_images item=sample_img }>
        document.getElementById("<{$sample_img.id}>_div").style.display="";
<{/foreach}>
        document.getElementById("show_image_btns").style.display="none";
        document.getElementById("sample_image_btns").style.display="";
    }
}
function HideSampleImage()
{
    document.getElementById("show_image_btns").style.display="";
    document.getElementById("sample_image_btns").style.display="none";
<{foreach from=$sample_images item=sample_img }>
    document.getElementById("<{$sample_img.id}>_div").style.display="none";
<{/foreach}>
}
function DoSmapleImageRotation(val)
{
    RotationVal = 1*document.getElementById('img_rotate').value;
    if (val < 0)
        val = 4+val;
    RotationVal = (RotationVal + val) % 4;
    document.getElementById('img_rotate').value = RotationVal;

<{foreach from=$sample_images item=sample_img }>
    document.getElementById("<{$sample_img.id}>_div").style.filter="progid:DXImageTransform.Microsoft.BasicImage(Rotation=" + RotationVal + ");";
    document.getElementById("<{$sample_img.id}>_div").style.width = document.getElementById("<{$sample_img.id}>").width+4;
    document.getElementById("<{$sample_img.id}>_div").style.height = document.getElementById("<{$sample_img.id}>").height+4;
<{/foreach}>
}
function DoSmapleImageZoom(val)
{
    ZoomVal = Math.round(1*document.getElementById('img_zoom').value)/10 + val;
    if (SampleImageWidth * ZoomVal < 200)
        ZoomVal = 200/SampleImageWidth;
    else if (SampleImageWidth * ZoomVal > 1000)
        ZoomVal = 1000/SampleImageWidth;
    document.getElementById('img_zoom').value = Math.floor(ZoomVal*10);

<{foreach from=$sample_images item=sample_img }>
    document.getElementById("<{$sample_img.id}>").width = SampleImageWidth * ZoomVal;
    document.getElementById("<{$sample_img.id}>").height = SampleImageHeight * ZoomVal;
    document.getElementById("<{$sample_img.id}>_div").style.width = document.getElementById("<{$sample_img.id}>").width+4;
    document.getElementById("<{$sample_img.id}>_div").style.height = document.getElementById("<{$sample_img.id}>").height+4;
<{/foreach}>
}
function ResetSampleImage()
{
    document.getElementById('img_zoom').value = 1;
    document.getElementById('img_rotate').value = 0;
    RotationVal = 0;
<{foreach from=$sample_images item=sample_img }>
    document.getElementById("<{$sample_img.id}>").width = SampleImageWidth;
    document.getElementById("<{$sample_img.id}>").height = SampleImageHeight;
    document.getElementById("<{$sample_img.id}>_div").style.filter="progid:DXImageTransform.Microsoft.BasicImage(Rotation=0);";
    document.getElementById("<{$sample_img.id}>_div").style.width = document.getElementById("<{$sample_img.id}>").width+4;
    document.getElementById("<{$sample_img.id}>_div").style.height = document.getElementById("<{$sample_img.id}>").height+4;
<{/foreach}>
}
</script> <input name="button" type='button' class='minibutton' onClick='DoSmapleImageRotation(-1);' value="&nbsp;<{$smarty.const.MI_SAMPLE_IMAGE_LEFT_ROTATE}>&nbsp;" />
              <input name="button" type='button' class='minibutton' onClick='DoSmapleImageZoom(0.2);' value="&nbsp;<{$smarty.const.MI_SAMPLE_IMAGE_ZOOM_IN}>&nbsp;" />
              <input name="button" type='button' class='minibutton' onClick='DoSmapleImageZoom(-0.2);' value="&nbsp;<{$smarty.const.MI_SAMPLE_IMAGE_ZOME_OUT}>&nbsp;" />
              <input name="button" type='button' class='minibutton' onClick='DoSmapleImageRotation(1);' value="&nbsp;<{$smarty.const.MI_SAMPLE_IMAGE_RIGHT_ROTATE}>&nbsp;" />
              <input name="button" type='button' class='minibutton' onClick='ResetSampleImage();' value="&nbsp;<{$smarty.const.MI_SAMPLE_IMAGE_RESET}>&nbsp;" />
              <input name="button" type='button' class='minibutton' onClick='HideSampleImage();' value="&nbsp;<{$smarty.const._HIDE}>&nbsp;" />
            </td>
          </tr>
          <tr>
            <td></td>
            <td align=left valign=center colspan=3> <div id='show_image_btns'>
                <input name="button" type='button' class='sbutton' onClick='ShowSampleImage();' value="&nbsp;<{$smarty.const.MI_SHOW_SAMPLE_IMAGE}>&nbsp;" />
              </div>
              <{foreach from=$sample_images item=sample_img }> <div id='<{$sample_img.id}>_div' style='filter:progid:DXImageTransform.Microsoft.BasicImage(0);'><img id='<{$sample_img.id}>' style='border: 2px dotted #8080ff;' onload='ShowSampleImage();HideSampleImage();' src='<{$sample_img.src}>'></div>
              <br/> <{/foreach}> </td>
          </tr>
          <{/if}>
          <script>
<{if $has_rare==true}>
    function display_rare(obj)
    {
        display_items = obj.value.indexOf("<{$smarty.const.MI_DISPLAY_RARE_ITEMS}>") > -1;
        if (display_items)
            document.getElementById('rare_counts').style.display = '';
        else
            document.getElementById('rare_counts').style.display = 'none';
<{  foreach from=$matchs item=match}>
<{    foreach from=$match item=line}>
<{      if $line.rare == 'Y'}>
        if (display_items || document.getElementById('line<{$line.pno}>_checked').checked)
            document.getElementById('line_<{$line.pno}>').style.display = '';
        else
            document.getElementById('line_<{$line.pno}>').style.display = 'none';
<{      /if}>
<{    /foreach}>
<{  /foreach}>
        if (display_items) {
            document.all.MI_DISPLAY_RARE_ITEMS.style.display = "none";
            document.all.MI_HIDE_RARE_ITEMS.style.display = "";
            // obj.value = "<{$smarty.const.MI_HIDE_RARE_ITEMS}>";
        } else {
            document.all.MI_DISPLAY_RARE_ITEMS.style.display = "";
            document.all.MI_HIDE_RARE_ITEMS.style.display = "none";
            // obj.value = "<{$smarty.const.MI_DISPLAY_RARE_ITEMS}>";
        }
    }
<{/if}>

<{foreach from=$serology_match_info key=serology_id item=info }>
    var imperfect_counts_<{$serology_id}>_display = false;
<{/foreach}>

    function display_imperfect_counts()
    {
        if (<{foreach from=$serology_match_info key=serology_id item=info }>
imperfect_counts_<{$serology_id}>_display || <{/foreach}> false)
            document.getElementById('imperfect_counts').style.display = '';
        else
            document.getElementById('imperfect_counts').style.display = 'none';
    }

<{foreach from=$serology_match_info key=serology_id item=info }>
    function display_imperfect_<{$serology_id}>(obj)
    {
        display_items = obj.value == '<{$smarty.const.MI_DISPLAY_IMPERFECT_ITEMS}>: <{$serology_id}>';
        imperfect_counts_<{$serology_id}>_display = display_items;
        display_imperfect_counts();

<{  foreach from=$matchs item=match}>
<{    foreach from=$match item=line}>
<{      if $line.imperfect == 'Y' && $line.serology_id==$serology_id }>
        if (display_items || document.getElementById('line<{$line.pno}>_checked').checked)
            document.getElementById('line_<{$line.pno}>').style.display = '';
        else
            document.getElementById('line_<{$line.pno}>').style.display = 'none';
<{      /if}>
<{    /foreach}>
<{  /foreach}>
        if (display_items)
            obj.value = '<{$smarty.const.MI_HIDE_IMPERFECT_ITEMS}>: <{$serology_id}>';
        else
            obj.value = '<{$smarty.const.MI_DISPLAY_IMPERFECT_ITEMS}>: <{$serology_id}>';
    }

<{/foreach}>
</script>
        </table>
        <br>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="center">
<input name="submit2" type='submit' class='btn_save' value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<{$smarty.const.MI_SAVE}>">
              <input name="button2" type='button' class='btn_uppage' onClick='history.go(-1);' value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<{$smarty.const.MI_BACK}>"></td>
          </tr>
        </table></td>
    </tr></table>
</form>
<script>
    clear_sample();
    clear_patient(true);
<{if !empty($sample_id)}>
    document.getElementById('sample_id').value = '<{$sample_id}>';
    ServerSync_GetSampleInfo();
    document.getElementById('dna_ext_method').focus();
<{else}>
    document.getElementById('sample_id').focus();
<{/if}>
</script>
